<?php

/**
 * descript:单一验证
 * User: blue
 * Date: 2018/9/13 16:37
 */

namespace rabbit\base;

use app\library\except\ParmasException;

class Regular
{
    /*验证邮箱规则*/
    public static function is_email($email_address){
        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
        $check=preg_match($pattern,$email_address);
        if(!$check) throw new ParmasException('请输入有效的邮箱');
        return true;
    }

    /**
     * 验证是不是整数
     * @param $value
     */
    public static function positive($value){
        if(is_numeric($value)&&is_int($value+0)&&($value+0)>=0){
            return true;
        }else{
            throw new ParmasException('请输入有效的整数');
        }
    }

    /**
     * 验证ids 字符串1,2,3
     * @param $value
     * @return bool
     */
    public  static function  checkIds($value){
        $arr=explode(',',$value);
        if(empty($value)) return false;
        foreach ($arr as $key=>$v){
            self::positive($v);
        }
        return true;
    }

}